#include <stdio.h>

#define max(a, b) (((a) > (b)) ? (a) : (b))

int smallestDivisor(int *nums, int numsSize, int threshold) {
//    int low = 1, high = 0;
//    for (int i = 0; i < numsSize; ++i) {
//        high = max(high, nums[i]);
//    }
//    while (low < high) {
//        int mid = low + ((high - low) >> 1);
//        int sum = 0;
//        for (int i = 0; i < numsSize; ++i) {
//            sum += (nums[i] + mid - 1) / mid;
//        }
//        if (sum > threshold) low = mid + 1;
//        else high = mid;
//    }
//    return low;
    int low = 1, high = 0;
    for (int i = 0; i < numsSize; ++i) {
        high = max(high, nums[i]);
    }
    high = nums[numsSize];
    while (low < high) {
        int mid = low + ((high - low) >> 1);
        int sum = 0;
        for (int i = 0; i < numsSize; ++i) {
            sum += (nums[i] + mid - 1) / mid;
        }
        if (sum > threshold) {
            low = mid + 1;
        } else {
            high = mid;
        }
    }
    return low;
}

int main() {
    int nums[4] = {1, 2, 5, 9}, threshold = 6;
    int ret = smallestDivisor(nums, 4, threshold);
    printf("%d", ret);
}